local db = TUNING.MOD_WEBBER_THE_TRAINER.ITEMS.staff_arachnidnexus.skill_1

---@class components
---@field staff_arachnidnexus_skill_healaccel component_staff_arachnidnexus_skill_healaccel

-- local function on_val(self, value)
    -- self.inst.replica.staff_arachnidnexus_skill_healaccel:SetVal(value)
-- end

---@class component_staff_arachnidnexus_skill_healaccel
---@field inst ent
local staff_arachnidnexus_skill_healaccel = Class(
---@param self component_staff_arachnidnexus_skill_healaccel
---@param inst ent
function(self, inst)
    self.inst = inst
    -- self.val = 0
end,
nil,
{
    -- val = on_val,
})

-- function staff_arachnidnexus_skill_healaccel:OnSave()
--     return {
--         -- val = self.val
--     }
-- end

-- function staff_arachnidnexus_skill_healaccel:OnLoad(data)
--     -- self.val = data.val or 0
-- end

---comment
---@param caster ent
---@param target ent
---@return boolean,string|nil
function staff_arachnidnexus_skill_healaccel:_Cast(caster,target)

    if not caster:HasTag('playerghost') and caster.components.health then
        local curhp = caster.components.health.currenthealth
        local maxhp = caster.components.health.maxhealth
        local reduce = db.reduce_caster_hp + maxhp * db.reduce_caster_maxhppercent
        if curhp > reduce then
            caster.components.health:DoDelta(-reduce)
            target:AddDebuff('buff_webbert_staff_arachnidnexus_skill_healaccel','buff_webbert_staff_arachnidnexus_skill_healaccel')
            return true
        else
            return false,'ACTION_WEBBERT_STAFF_ARACHNIDNEXUS_HEALACCEL_failed_for_lackofhp'
        end
    end
    return false
end

---comment
---@param caster ent
---@param target ent
---@return boolean
function staff_arachnidnexus_skill_healaccel:Cast(caster,target)
    -- 无论怎样都返回true,这样就可以不用管失败提示,自己写talker:say
    local success,reason = self:_Cast(caster,target)
    if reason then
        if caster.components.talker then
            caster.components.talker:Say(STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS[reason])
        end
    end
    return true
end

return staff_arachnidnexus_skill_healaccel